<!-- -*- mode: R -*- -->
  <!--
  ## This program is fre esoftware: you can redistribute it and/or modify
  ## it under the terms of the GNU General Public License as published by
  ## the Free Software Foundation, either version 3 of the License, or
  ## any later version.
  ##
  ## This program is distributed in the hope that it will be useful,
  ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ## GNU General Public License for more details.
  ##
  ## You should have received a copy of the GNU General Public License
  ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
  
  <%
setContentType("text/html")
#RApacheOutputErrors(TRUE)
options(hverbose=FALSE,verbose=FALSE)
%>
  
<html>
<head>
<title>Strategico: index</title>
</head>
<body>
  <%
strategico.home <- as.character(Sys.getenv("STRATEGICO_HOME"))
source(file.path(strategico.home, "strategico_util.R"))
project.name <- ifelse(is.null(GET$project), "sample", GET$project)
%>
  <center>
<h1><img src="http://www.r-project.org/Rlogo.jpg" />Strategico :: Project <%=project.name%></h1>
  </center>
<form action="search-item.brew" method="GET">
  <%=BuildHtmlElement_input(name="project", default=project.name, type="hidden")%>
  <input type="submit" name="eval" value="Search item">
</form>
<form method="GET">
  <input type="submit" name="show_statistics" value="Show statistics">
  <input type="submit" name="export_db" value="Export DB to CSV">
  <input type="submit" name="empty_db" value="Empty DB tables">
  <input type="submit" name="import_db" value="Import DB">
</form>
<form method="GET">
  <input type="submit" name="change_project" value="Change project">
  <%=BuildFormElement_project(label="", default=project.name)%>
</form>

<%
db.channel <- DB.Connect()
%>

<%
if (!is.null(GET$empty_db)) {
  Project.DB.Empty(project.name=project.name, db.channel=db.channel)
  GET$show_statistics <- TRUE
}

if (!is.null(GET$export_db)) {
  Project.DBExportTables2Csv(project.name=project.name, db.channel=db.channel)
  project.url <- Project.GetUrl(project.name=project.name)
  link <- paste("<br /><br /><a href=", project.url, ">Goto XLS files.</a>", sep="")
  cat(link)
}
if (!is.null(GET$show_statistics)) {
  stats <- Project.GetStatistics(project.name=project.name, db.channel=db.channel)
  print(xtable(t(as.data.frame(stats))), type="html")
}

%>

<%
DB.Close(db.channel)
%>

<% ShowTemplate('footer') %>

